#include "stdafx.h"
#include "net/ICMPPacket.hpp"

NET_NAMESPACE_BEGIN

CICMPPacket::CICMPPacket(CIPAddress::Family family, int dataSize) : m_pImpl(0)
{
	if (family == CIPAddress::IPv4)
		m_pImpl = new CICMPv4PacketImpl(dataSize);
#if defined(JH_HAVE_IPv6)
	else if (family == CIPAddress::IPv6)
		throw NotImplementedException("ICMPv6 packets not implemented.");
#endif
	else throw InvalidArgumentException("Invalid or unsupported address family passed to ICMPPacket");
}

CICMPPacket::~CICMPPacket()
{
	delete m_pImpl;
}

void CICMPPacket::setDataSize(int dataSize)
{
	m_pImpl->setDataSize(dataSize);
}

int CICMPPacket::getDataSize() const
{
	return m_pImpl->getDataSize();
}

int CICMPPacket::packetSize() const
{
	return m_pImpl->packetSize();
}

int CICMPPacket::maxPacketSize() const
{
	return m_pImpl->maxPacketSize();
}

const UInt8* CICMPPacket::packet()
{
	return m_pImpl->packet();
}

struct timeval CICMPPacket::time(UInt8* buffer, int length) const
{
	return m_pImpl->time(buffer, length);
}

bool CICMPPacket::validReplyID(UInt8* buffer, int length) const
{
	return m_pImpl->validReplyID(buffer, length);
}

std::string CICMPPacket::errorDescription(UInt8* buffer, int length)
{
	return m_pImpl->errorDescription(buffer, length);
}

std::string CICMPPacket::typeDescription(int typeId)
{
	return m_pImpl->typeDescription(typeId);
}

NET_NAMESPACE_END
